from tortoise.models import Model
from tortoise import fields


class User(Model):
    id = fields.IntField(pk=True)
    username = fields.CharField(max_length=32, unique=True, description="用户名")
    password = fields.CharField(max_length=64, description="密码")  # 密码应加密存储
    email = fields.CharField(max_length=64, unique=True, description="邮箱")
    is_active = fields.BooleanField(default=True, description="账户是否激活")
    created_at = fields.DatetimeField(auto_now_add=True, description="创建时间")
    crawl_count = fields.IntField(default=0, description="爬取次数")

    # 一对多的关系
    groups = fields.ForeignKeyField("models.Group", related_name="users")


class Group(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=32, unique=True, description="用户组名称")
    level = fields.IntField(description="权限等级")  # 可以存储权限标识
